package com.homily.com.test0;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import org.w3c.dom.Text;

public class CounterActivity extends AppCompatActivity implements View.OnClickListener{
    protected EditText cnum1;
    protected EditText cnum2;
    protected TextView cresult;
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_counter);
        findViewById(R.id.bt_counter).setOnClickListener(this);
        cnum1=findViewById(R.id.et_num1);
        cnum2=findViewById(R.id.et_num2);
        cresult=findViewById(R.id.tv_result);
    }


    @Override
    public void onClick(View v) {
        int id =v.getId();
        switch (id) {
            case R.id.bt_counter:
            String mnum1=    cnum1.getText().toString();
            String mnum2=    cnum2.getText().toString();
            if (TextUtils.isEmpty(mnum1)||TextUtils.isEmpty(mnum2)){
                Toast.makeText(this,"输入不能为空",Toast.LENGTH_SHORT).show();
            }else{
                Double num1 = Double.parseDouble(mnum1);
                Double num2 = Double.parseDouble(mnum2);
                Double result = num1 + num2;
                cresult.setText(result + "");
            }
            break;
        }
    }
}
